function [ bnd ] = messageMultiplication1(messages, proposal, p_acs, ndists_ndac, var_m)

[N_samples, ~] = size(proposal);
[n_ac,~] = size(p_acs);
[n_nd, ~] = size(messages);

%calculate weigths
weights = 1;
for i=1:n_ac
    dist_sq = (proposal(:,1)-p_acs(i,1)).^2+(proposal(:,2)-p_acs(i,2)).^2;
    wtmp = exp(-1/(2*var_m) * (ndists_ndac(i) - sqrt(dist_sq)).^2);
    weights = weights .* wtmp;
    weights = 10^10 * 1/sum(weights) * weights;
end

for i=1:n_nd
    tmp = messages{i};
    wtmp = zeros(N_samples,1);
    for j=1:N_samples
        sq = (proposal(j,1)-tmp(:,1)).^2+(proposal(j,2)-tmp(:,2)).^2;
        wtmp(j) = sum(exp(-1/(2*var_m) * sq));
    end
    weights = weights .* wtmp;
    weights = 10^10 * 1/sum(weights) * weights;
end

%normalise weights
weights = 1/sum(weights) * weights;

if( (sum(isnan(weights)) + sum(isinf(weights))) > 0)
    bnd = NaN*ones(N_samples,4);
    return
end

%resample
tmp = resampleSystematic(weights,N_samples);

bnd = proposal(tmp,:);
end

